﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DataAccess;
namespace SQT.tracnghiem.Ajax.ASP.Lesson
{
    public partial class add_new_grammar : System.Web.UI.Page
    {
        public int id;
        public string grammar;
        protected void Page_Load(object sender, EventArgs e)
        {
            string name = Request.QueryString["name"];
            int lesson = int.Parse(Request.QueryString["lesson"]);
            var get_grammar= (from p in new TblLessonGrammarController().FetchAll() orderby p.GramIndex ascending where p.LessonId==lesson select p);
            if (get_grammar.ToList().Count != 0)
            {
                int get_last_index = (int)get_grammar.Last().GramIndex + 1;

                new TblLessonGrammarController().Insert(lesson, name, "", "", "", true, get_last_index);
                var get_last = new TblLessonGrammarController().FetchAll().Last();
                id = get_last.GramId;
                grammar = name;
            }
            else
            {
                new TblLessonGrammarController().Insert(lesson, name, "", "", "", true, 0);
                var get_last = new TblLessonGrammarController().FetchAll().Last();
                id = get_last.GramId;
                grammar = name;
            }
        }
    }
}